package com.hzw.jdbc.day02;

import com.hzw.utils.JdbcUtil;

import java.sql.*;

public class Util01 {
    private static Connection connection;
    static{
        try {
            connection = JdbcUtil.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static int update(String sql){
        PreparedStatement preparedStatement = null;
        int i = 0;
        try {
            preparedStatement = connection.prepareStatement(sql);
            i = preparedStatement.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }


    public static ResultSet query(String sql){
        Statement statement = null;
        ResultSet i = null;
        try {
            statement = connection.createStatement();
            i = statement.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }


    public static void close(){
        JdbcUtil.release(connection,null,null);
    }

}
